﻿using MvvmCross.Core.ViewModels;
using Sidvall.UI.Messaging;
using Sidvall.WorkItemManager.UI.Messaging;
using System.Windows.Input;

namespace Sidvall.WorkItemManager.UI.ViewModels
{
    public class ToolViewModel : Sidvall.WorkItemManager.UI.ViewModels.Core.ViewModelBase
    {
        #region CanGoBack

        public bool CanGoBack
        {
            get
            {
                return Sidvall.UI.SystemContext.Current.NavigationManager.CanGoBack;
            }
        }

        #endregion
        #region CanGoForward

        public bool CanGoForward
        {
            get
            {
                return Sidvall.UI.SystemContext.Current.NavigationManager.CanGoForward;
            }
        }

        #endregion

        #region ConnectToServerCommand

        public ICommand ConnectToServerCommand
        {
            get
            {
                return new MvxCommand(() => ConnectToServer());
            }
        }

        #endregion
        #region ConnectToServer

        public void ConnectToServer()
        {
            ServerParameter serverParameter;

            serverParameter = new ServerParameter()
            {
                RedirectOnConnected = true,
                ConnectAutomatically = false,
            };

            ShowViewModel<ServerViewModel>(serverParameter, false, "CenterContent");
        }

        #endregion
        #region GoBackCommand

        public ICommand GoBackCommand
        {
            get
            {
                return new MvxCommand(() => GoBack());
            }
        }

        #endregion
        #region GoBack

        public void GoBack()
        {
            ChangePresentation(Sidvall.UI.ViewModels.ViewModelActionType.GoBack);
        }

        #endregion
        #region GoForwardCommand

        public ICommand GoForwardCommand
        {
            get
            {
                return new MvxCommand(() => GoForward());
            }
        }

        #endregion
        #region GoForward

        public void GoForward()
        {
            ChangePresentation(Sidvall.UI.ViewModels.ViewModelActionType.GoForward);
        }

        #endregion
        #region ShowUserConfigurationCommand

        public ICommand ShowUserConfigurationCommand
        {
            get
            {
                return new MvxCommand(ShowUserConfiguration);
            }
        }

        #endregion
        #region ShowUserConfiguration

        public void ShowUserConfiguration()
        {
            ShowViewModel<UserConfigurationViewModel>((object)null, false, "CenterContent");
        }

        #endregion
        #region ShowDocumentationCommand

        public ICommand ShowDocumentationCommand
        {
            get
            {
                return new MvxCommand(ShowDocumentation);
            }
        }

        #endregion
        #region ShowDocumentation

        public void ShowDocumentation()
        {
            ShowViewModel<DocumentationViewModel>((object)null, false, "CenterContent");
        }

        #endregion
        #region ShowHelpCommand

        public ICommand ShowHelpCommand
        {
            get
            {
                return new MvxCommand(() => ShowHelp());
            }
        }

        #endregion
        #region ShowHelp

        public void ShowHelp()
        {
            ShowViewModel<HelpViewModel>((object)null, false, "CenterContent");
        }

        #endregion

        #region OnNavigation

        private void OnNavigation(NavigationMessage item)
        {
            RaisePropertyChanged("CanGoBack");
            RaisePropertyChanged("CanGoForward");
        }

        #endregion
        #region OnServerManagerMessage

        private void OnServerManagerMessage(ServerManagerMessage item)
        {
            RaiseAllPropertiesChanged();
        }

        #endregion

        #region Start

        public override void Start()
        {
            Subscribe<NavigationMessage, ServerManagerMessage>(OnNavigation, OnServerManagerMessage);
        }

        #endregion
    }
}
